import 'package:appflutterhomeschool/model/notification_model.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/route/application.dart';
import 'package:appflutterhomeschool/route/routes.dart';
import 'package:appflutterhomeschool/ui/widgets/image_widget.dart';
import 'package:appflutterhomeschool/utils/float_tuils/speed_dial.dart';
import 'package:appflutterhomeschool/utils/float_tuils/speed_dial_child.dart';
import 'package:appflutterhomeschool/utils/letter_display_utils.dart';
import 'package:appflutterhomeschool/utils/utils.dart';
import 'package:appflutterhomeschool/view_model/my_app_view_model.dart';
import 'package:appflutterhomeschool/view_model/notice/notice_view_model.dart';
import 'package:appflutterhomeschool/view_model/login/register_view_model.dart';
import 'package:flukit/flukit.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'my_app_bar.dart';

///图片占位符
class ProgressView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: SizedBox(
        width: 24.0,
        height: 24.0,
        child: CircularProgressIndicator(strokeWidth: 2.0),
      ),
    );
  }
}

///控件阴影组件
class ShadowWidget extends StatelessWidget {
  final Widget childWidget;

  //最外面距离边界的距离
  final EdgeInsetsGeometry externalPadding;

  //投影大小                    圆角的大小
  final double doubleElvation, circularDouble;
  final GestureTapCallback onTap;

  //里面的属性
  final EdgeInsetsGeometry withinPadding;

  ShadowWidget({
    this.childWidget,
    this.externalPadding,
    this.doubleElvation,
    this.circularDouble,
    this.withinPadding,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: externalPadding ?? EdgeInsets.all(ScreenUtil().setWidth(35)),
      child: Material(
        elevation: doubleElvation ?? 5.0,
        shadowColor: Colors.grey.withOpacity(0.5),
        borderRadius: BorderRadius.circular(circularDouble ?? 10),
        child: InkWell(
          borderRadius: BorderRadius.circular(circularDouble ?? 10),
          child: Container(
            padding: withinPadding ??
                EdgeInsets.only(
                    top: ScreenUtil().setWidth(35),
                    left: ScreenUtil().setWidth(35),
                    right: ScreenUtil().setWidth(35),
                    bottom: 0),
            child: childWidget,
          ),
          onTap: onTap ?? null,
        ),
      ),
    );
  }
}

///注册协议
class RegistrationAgreementWidget extends StatelessWidget {
  final RegisterViewModel viewModel;

  RegistrationAgreementWidget(this.viewModel);

  @override
  Widget build(BuildContext context) {
    return Visibility(
      visible: viewModel.pageTag == 0,
      child: RichText(
        text: TextSpan(children: [
          WidgetSpan(
            child: GestureDetector(
              child: Container(
                margin: EdgeInsets.only(bottom: 2, right: 10),
                child: Image.asset(
                  Utils.getImgPath(viewModel.consentAgreement
                      ? "login_tongyi_true"
                      : "login_tongyi_false"),
                ),
              ),
              onTap: () => viewModel.initEvent(1),
            ),
          ),
          TextSpan(
            text: "我已阅读并同意",
            style: TextStyles.textGray37,
          ),
          TextSpan(
              text: '《xx协议》',
              style: TextStyles.textBlue37,
              recognizer: viewModel.recognizer1),
          TextSpan(
            text: "和",
            style: TextStyles.textGray37,
          ),
          TextSpan(
              text: '《隐私政策》',
              style: TextStyles.textBlue37,
              recognizer: viewModel.recognizer1),
        ]),
      ),
    );
  }
}

///手机号码输入框
class TextFieldWidget extends StatelessWidget {
  final int length;
  final TextInputType textInputType;
  final String hintText;
  final ValueChanged<String> valueChanged;
  final Widget iconEye, suffix;
  final bool obscureText;
  final TextEditingController textEditingController;

  TextFieldWidget(
      {this.length,
      this.textInputType,
      this.suffix,
      this.valueChanged,
      this.hintText,
      this.iconEye,
      this.obscureText,
      this.textEditingController});

  @override
  Widget build(BuildContext context) {
    return TextField(
//是否显示密码
      obscureText: obscureText ?? false,
//是否禁用
      autofocus: false,
      controller: textEditingController,
      keyboardType: textInputType ?? TextInputType.number,
      maxLength: length ?? 11,
      style: TextStyles.textDark43,
      decoration: InputDecoration(
          contentPadding: EdgeInsets.only(
              bottom: ScreenUtil().setWidth(74),
              top: ScreenUtil().setWidth(74)),
          focusedBorder: UnderlineInputBorder(
//选中时外边框颜色
            borderSide: BorderSide(color: Colors.blue),
          ),
          hintText: hintText ?? '请输入内容',
          counterText: "",
//此处控制最大字符是否显示
          hintStyle: TextStyles.textGrey43,
          suffix: suffix,
          suffixIcon: iconEye),
      onChanged: valueChanged,
    );
  }
}

class TextBlueWidget extends StatelessWidget {
  final String name;
  final double marginLeft;

  TextBlueWidget({this.name, this.marginLeft});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(left: marginLeft ?? 0),
      alignment: Alignment.center,
      width: ScreenUtil().setWidth(86),
      height: ScreenUtil().setWidth(43),
      decoration: BoxDecoration(
          color: Colors.blue[50], borderRadius: BorderRadius.circular(3)),
      child: Text(
        name ?? "内容",
        style: TextStyles.textBlue27,
      ),
    );
  }
}

///首页listView列表
class NoticeListViewWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    NoticeViewModel noticeViewModel = Provider.of(context);

    return noticeViewModel.notificationList.length == 0
        ? Center(
            child: Text("数据加载中"),
          )
        : ListView.builder(
            physics: NeverScrollableScrollPhysics(), //禁用滑动事件
            itemCount: noticeViewModel.notificationList.length,
            shrinkWrap: true,
            itemBuilder: _listItemView,
          );
  }

  Widget _listItemView(context, index) {
    NoticeViewModel noticeViewModel = Provider.of<NoticeViewModel>(context);
    NotificationModel notificationModel =
        noticeViewModel.notificationList[index];
    String writeRead = "";
    if (notificationModel?.write != 0) {
      writeRead = "${notificationModel?.write ?? 0}人已确认";
    }
    if (notificationModel.noRead != 0) {
      writeRead = "${notificationModel?.noRead ?? 0}人未读";
    }
    if (notificationModel.noRead != 0 && notificationModel?.write != 0) {
      writeRead =
          "${notificationModel?.write ?? 0}人已确认\t·\t${notificationModel?.noRead ?? 0}人未读";
    }
    return Column(
      children: <Widget>[
        //日期
        ShadowWidget(
          externalPadding: EdgeInsets.only(
              left: ScreenUtil().setWidth(35),
              right: ScreenUtil().setWidth(35),
              top: ScreenUtil().setWidth(35)),
          withinPadding: EdgeInsets.fromLTRB(10, 3, 10, 5),
          childWidget: Text(
            notificationModel?.datetime ?? "",
            style: TextStyles.textGrayA231,
          ),
        ),
        //主体UI
        ShadowWidget(
          externalPadding: EdgeInsets.only(
              left: ScreenUtil().setWidth(35),
              right: ScreenUtil().setWidth(35),
              top: ScreenUtil().setWidth(35)),
          childWidget: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              //红点
              Container(
                width: double.maxFinite,
                alignment: Alignment.centerRight,
                child: Container(
                  width: 5,
                  height: 5,
                  decoration: BoxDecoration(
                      color:
                          notificationModel.isRead ? Colors.white : Colors.red,
                      borderRadius: BorderRadius.circular(5)),
                ),
              ),
              Text.rich(TextSpan(children: [
                WidgetSpan(
                    alignment: PlaceholderAlignment.middle,
//                    类型：String  必有字段  备注：通知类型（表单：Form,任务：Task，通知：Notification，讨论:Chart）
                    child: Visibility(
                      visible: notificationModel.notificationString != null,
                      child: TextBlueWidget(
                          name: notificationModel?.notificationString ?? ""),
                    )),
                TextSpan(
                    text: "\t${notificationModel.title}",
                    style: TextStyles.textDark43),
              ])),
              SizedBox(height: ScreenUtil().setWidth(37)),
              ItemTopWidget(
                imageUrl: notificationModel.senderImg,
                className:
                    LetterDisplayUtils.maxLength(notificationModel.senderName),
                textContent: notificationModel.notificationCls,
                time: notificationModel?.timeDivision ?? "",
                visibility: true,
              ),
              SizedBox(height: ScreenUtil().setWidth(40)),
              GestureDetector(
                child: Text(
                  notificationModel.msg ?? "",
                  maxLines: 2,
                  style: TextStyles.textGrayA231,
                  overflow: TextOverflow.ellipsis,
                ),
                onTap: () {},
              ),
              //老师端 几人确认 几人未读
              Visibility(
                visible: noticeViewModel.identity,
                child: Container(
                  margin: EdgeInsets.only(
                      top: ScreenUtil().setWidth(33),
                      bottom: ScreenUtil().setWidth(34)),
                  child: Text.rich(TextSpan(children: [
                    TextSpan(text: "进行中", style: TextStyles.textOrange30),
                    TextSpan(text: "·$writeRead", style: TextStyles.textBlue27),
                  ])),
                ),
              ),
//              Container(
//                child: Text(writeRead, style: TextStyles.textBlue30),
//                margin: EdgeInsets.only(top: ScreenUtil().setWidth(34)),
//              ),
              SizedBox(height: ScreenUtil().setWidth(41)),
              //家长端 显示状态
              Visibility(
                visible:
                    !noticeViewModel.identity && notificationModel.needConfirm,
                child: GestureDetector(
                  child: Container(
                    padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(41)),
                    child: Text("确认收到"),
                    alignment: Alignment(0, 0),
                  ),
                  onTap: () => noticeViewModel.sureReedOnTap(index),
                ),
              ),
            ],
          ),
          onTap: () => noticeViewModel.itemOnTap(index),
        ),
      ],
    );
  }
}

class ItemTopWidget extends StatelessWidget {
  final String textContent, className, imageUrl, time;
  final bool visibility;

  ItemTopWidget(
      {this.textContent,
      this.visibility,
      this.className,
      this.imageUrl,
      this.time});

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        ImageWidget(
          imageUrl: imageUrl,
        ),
        Container(
          padding: EdgeInsets.only(left: ScreenUtil().setWidth(22)),
          child: Text(
            "\t$className",
            style: TextStyles.textDark31,
            overflow: TextOverflow.ellipsis,
          ),
        ),
        Text("\t${textContent}", style: TextStyles.textGray30),
        Spacer(),
        Visibility(
          visible: visibility ?? true,
          child: Text(time ?? "", style: TextStyles.textGray30),
        )
      ],
    );
  }
}

///首页浮动按钮  信件浮动按钮
class FloatingButtonWidget extends StatefulWidget {
  final bool visible;

  FloatingButtonWidget({this.visible});

  @override
  _FloatingButtonWidgetState createState() => _FloatingButtonWidgetState();
}

class _FloatingButtonWidgetState extends State<FloatingButtonWidget> {
  bool oneBool = false;

  @override
  Widget build(BuildContext context) {
    return SpeedDial(
        visible: widget.visible,
        elevation: 0,
        backgroundColor: Colors.transparent,
        overlayColor: Colors.black,
        child: Image.asset(
          Utils.getImgPath(oneBool ? "shouye_guanbi" : "xinjian"),
          width: ScreenUtil().setWidth(103),
          height: ScreenUtil().setWidth(103),
        ),
        onValueTap: (value) {
          oneBool = !oneBool;
          setState(() {});
        },
        children: [
          SpeedDialChild(
              child: Image.asset(
                Utils.getImgPath("shouye_taolun"),
                width: ScreenUtil().setWidth(49),
                height: ScreenUtil().setWidth(49),
              ),
              label: '讨论',
              onTap: () => Application().navigatePushToPage(
                  context, Routes.custumNotificationsPage, {"pageTag": 1})),
          SpeedDialChild(
              child: Image.asset(
                Utils.getImgPath("rshouye_enwu"),
                width: ScreenUtil().setWidth(49),
                height: ScreenUtil().setWidth(49),
              ),
              label: '任务',
              labelStyle: TextStyle(fontSize: 18.0),
              onTap: () => Application().navigatePushToPage(
                  context, Routes.custumNotificationsPage, {"pageTag": 2})),
          SpeedDialChild(
            child: Image.asset(
              Utils.getImgPath("shouye_biaodan"),
              width: ScreenUtil().setWidth(49),
              height: ScreenUtil().setWidth(49),
            ),
            label: '表单',
            labelStyle: TextStyle(fontSize: 18.0),
            onTap: () => Application()
                .navigatePushToPage(context, Routes.newFormPage, {}),
          ),
          SpeedDialChild(
            child: Image.asset(
              Utils.getImgPath("shouye_tongzhi"),
              width: ScreenUtil().setWidth(49),
              height: ScreenUtil().setWidth(49),
            ),
            label: '通知',
            labelStyle: TextStyle(fontSize: 18.0),
            onTap: () => Application()
                .navigatePushToPage(context, Routes.newNotificationPage, {}),
          ),
        ]);
  }
}

class WebViewWidget extends StatelessWidget {
  final String title;
  final String url;

  WebViewWidget({this.title, this.url});

  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
      appBar: MyAppBar2(title: title ?? ""),
      url: url ??
          "http://47.110.253.251/templates-static/templates/html/%E5%B7%A9%E5%BF%97%E6%9D%B0%E7%9A%84%E7%8F%AD%E7%BA%A7%E7%8F%AD%E7%BA%A7%E6%8A%A5%E5%91%8A%E6%B5%8B%E8%AF%95%E7%8F%AD%E7%BA%A7%E6%B5%8B%E8%AF%84%E6%8A%A5%E5%91%8A_83.html",
      // 登录的URL
      // 允许网页缩放
      withZoom: false,
      // 允许LocalStorage
      withLocalStorage: false,
      withJavascript: true, // 允许执行js代码
    );
  }
}

///我的页面 界面跳转组件
class UserInformationWidget extends StatelessWidget {
  final String image;
  final String userName;
  final String identity, clsNum;

  UserInformationWidget(
      {this.image, this.userName, this.identity, this.clsNum});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        top: ScreenUtil().setWidth(202),
        left: ScreenUtil().setWidth(46),
        right: ScreenUtil().setWidth(46),
        bottom: ScreenUtil().setWidth(69),
      ),
      color: Colors.white,
      width: double.maxFinite,
      child: Row(
        children: <Widget>[
          CircleAvatar(
//头像半径
            radius: ScreenUtil().setWidth(87.5),
//头像图片 -> NetworkImage网络图片，AssetImage项目资源包图片, FileImage本地存储图片
            backgroundImage: NetworkImage(image),
          ),
          SizedBox(width: 10),
          Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text.rich(TextSpan(children: [
                TextSpan(
                    text: userName ?? "用户昵称", style: TextStyles.textDarkBold52),
                WidgetSpan(
                    alignment: PlaceholderAlignment.middle,
                    child: TextBlueWidget(
                      name: identity,
                      marginLeft: 10,
                    )),
              ])),
              SizedBox(height: 10),
              Text(clsNum, style: TextStyles.textGray27),
            ],
          )
        ],
      ),
    );
  }
}

/// =========================学情=================================

class AcademicItemTitle extends StatelessWidget {
  final bool visible, academicVisible;
  final String title, content;
  final TextStyle titleStyle, contentStyle;
  final EdgeInsetsGeometry padding;
  final GestureTapCallback onTap;

  AcademicItemTitle(
      {this.visible,
      this.title,
      this.academicVisible,
      this.padding,
      this.content,
      this.titleStyle,
      this.onTap,
      this.contentStyle});

  @override
  Widget build(BuildContext context) {
    return Visibility(
      visible: academicVisible ?? true,
      child: Padding(
        padding: padding ??
            EdgeInsets.only(
              left: ScreenUtil().setWidth(35),
              right: ScreenUtil().setWidth(35),
              top: ScreenUtil().setWidth(52),
              bottom: ScreenUtil().setWidth(35),
            ),
        child: Row(
          children: <Widget>[
            Expanded(
              child: Text(
                title ?? "请输入标题",
                style: titleStyle ?? TextStyles.textDark43,
              ),
            ),
            Visibility(
              visible: visible ?? false,
              child: GestureDetector(
                onTap: onTap,
                child: Text.rich(TextSpan(children: [
                  TextSpan(
                      text: content ?? "查看全部",
                      style: contentStyle ?? TextStyles.textGray30),
                  TextSpan(
                    text: "\t>",
                    style: TextStyles.textGray30,
                  ),
                ])),
              ),
            )
          ],
        ),
      ),
    );
  }
}

class AcademicListView extends StatelessWidget {

 final List list;

  AcademicListView(this.list);

  @override
  Widget build(BuildContext context) {
    return ShadowWidget(
      externalPadding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(35), 0,
          ScreenUtil().setWidth(35), ScreenUtil().setWidth(35)),
      withinPadding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(43), 0,
          ScreenUtil().setWidth(43), ScreenUtil().setWidth(69)),
      childWidget: ListView.builder(
          physics: NeverScrollableScrollPhysics(), //禁用滑动事件
          shrinkWrap: true,
          itemCount: list.length,
          itemBuilder: (context, index) {
            return AcademicItemTitle(
              title: list[index]??"",
              titleStyle: TextStyles.textDark37,
              content: "已完成",
              visible: true,
              padding: EdgeInsets.only(top: ScreenUtil().setWidth(69)),
            );
          }),
    );
  }
}

class GradientCircularProgressRoute extends StatefulWidget {
  final double endDouble;
  final String student, knowledgePoints;

  GradientCircularProgressRoute(
      {this.endDouble, this.student, this.knowledgePoints});

  @override
  GradientCircularProgressRouteState createState() {
    return new GradientCircularProgressRouteState();
  }
}

class GradientCircularProgressRouteState
    extends State<GradientCircularProgressRoute> with TickerProviderStateMixin {
  AnimationController _animationController;
  double pi = 0.1;

  @override
  void initState() {
    super.initState();
    _animationController =
        new AnimationController(vsync: this, duration: Duration(seconds: 3));
    _animationController.addListener(() {
      _animationController.animateTo(widget.endDouble ?? 0.5);
    });
    _animationController.forward();
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            AnimatedBuilder(
              animation: _animationController,
              builder: (BuildContext context, Widget child) {
                return Stack(
                  alignment: Alignment.center,
                  children: <Widget>[
                    GradientCircularProgressIndicator(
                      colors: [
                        Colors.cyan[200],
                        Colors.cyan[300],
                        Colors.cyan[400],
                        Colors.cyan[500],
                        Colors.cyan[400],
                        Colors.cyan[300],
                        Colors.cyan[200],
                      ],
                      radius: ScreenUtil().setWidth(100),
                      stokeWidth: 5,
                      value: _animationController.value,
                      strokeCapRound: true,
                    ),
                    Column(
                      children: <Widget>[
                        Text("${(_animationController.value * 100).toInt()}%",
                            style: TextStyles.textDark37),
                        Text(widget.knowledgePoints ?? "掌握程度",
                            style: TextStyles.textGray27),
                      ],
                    ),
                  ],
                );
              },
            ),
            SizedBox(height: ScreenUtil().setWidth(21)),
            Text(
              widget.student ?? "知识点",
              style: TextStyles.textDark37,
            ),
          ],
        ),
      ),
    );
  }
}

/// =========================学情=================================
/// =========================我的页面组件=================================
///选择身份
class SwitchIdentityWidget extends StatelessWidget {
  final String image;
  final bool visible;
  final GestureTapCallback onTap;

  SwitchIdentityWidget({this.image, this.visible, this.onTap});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Stack(
        children: <Widget>[
          Image.asset(Utils.getImgPath(image)),
          Positioned(
            bottom: 20,
            left: 15,
            child: Visibility(
              visible: visible,
              child: Image.asset(Utils.getImgPath("xuanzhong")),
            ),
          )
        ],
      ),
      onTap: onTap,
    );
  }
}

///刷新底部组件
class CustomFotterWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CustomFooter(
      builder: (BuildContext context, LoadStatus mode) {
        Widget body;
        if (mode == LoadStatus.idle) {
          body = Text("上拉加载");
        } else if (mode == LoadStatus.loading) {
          body = CupertinoActivityIndicator();
        } else if (mode == LoadStatus.failed) {
          body = Text("加载失败！单击“重试”！");
        } else if (mode == LoadStatus.canLoading) {
          body = Text("释放加载更多");
        } else {
          body = Text("没有更多数据");
        }
        return Container(
          height: 55.0,
          child: Center(child: body),
        );
      },
    );
  }
}

///空列表展示组件
class NullListWidget extends StatelessWidget {
  final String tipsContnt;

  NullListWidget({this.tipsContnt});

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Image.asset(Utils.getImgPath("kong")),
        Text(
          tipsContnt ?? "",
          style: TextStyles.textDark37,
        )
      ],
    );
  }
}

///公共的横向展示列表图片可以删除

class ListViewWidget extends StatelessWidget {
  //判断是加载文件还是路径
  final int type;
  final List listImage;
  final ValueChanged<int> onTapIndex;
  final double setWidth;
  final bool shanchuFujian;

  ListViewWidget(
      {this.listImage,
      this.type,
      this.onTapIndex,
      this.setWidth,
      this.shanchuFujian});

  @override
  Widget build(BuildContext context) {
    return Visibility(
      visible: listImage.length != 0,
      child: Container(
        margin: EdgeInsets.only(top: 10, bottom: 10),
        alignment: Alignment.centerLeft,
        height: 100,
        child: ListView.builder(
            shrinkWrap: true,
            scrollDirection: Axis.horizontal,
            itemCount: listImage.length,
            itemBuilder: (context, index) {
              return Container(
                padding: EdgeInsets.all(3),
                alignment: Alignment.topRight,
                height: 100,
                width: setWidth ?? 150,
                margin: EdgeInsets.only(left: 10),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  image: DecorationImage(
                    image: NetworkImage(listImage[index]),
                    fit: BoxFit.cover,
                  ),
                ),
                child: Visibility(
                  visible: shanchuFujian ?? true,
                  child: GestureDetector(
                    onTap: () => onTapIndex(index),
                    child: Image.asset(Utils.getImgPath("shanchu_fujian")),
                  ),
                ),
              );
            }),
      ),
    );
  }
}

///收件人组件
class AddresseeWidget extends StatelessWidget {
  final GestureTapCallback onTap;
  final String addressee;
  final int page;

  AddresseeWidget({this.onTap, this.addressee, this.page});

  @override
  Widget build(BuildContext context) {
    String leftText = page == 4 ? "布置范围" : "收件人";
    return Container(
      margin: EdgeInsets.only(
          left: ScreenUtil().setWidth(31), right: ScreenUtil().setWidth(31)),
      decoration: BoxDecoration(
          border:
              Border(bottom: BorderSide(color: Colors.grey[200], width: 0.5))),
      padding: EdgeInsets.only(
          top: ScreenUtil().setWidth(31), bottom: ScreenUtil().setWidth(31)),
      child: Row(
        children: <Widget>[
          Text("$leftText：$addressee", style: TextStyles.textGray37),
          Expanded(child: Text("")),
          GestureDetector(
            onTap: onTap,
            child: Icon(Icons.add_circle_outline,
                color: Colors.blue, size: ScreenUtil().setWidth(63)),
          )
        ],
      ),
    );
  }
}

///回复标题组件
class ReplyTitleWidget extends StatelessWidget {
  final String leftTitle;
  final ValueChanged<String> onChanged;
  final TextEditingController textEditingController;

  ReplyTitleWidget(
      {this.leftTitle, this.onChanged, this.textEditingController});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(
          left: ScreenUtil().setWidth(31), right: ScreenUtil().setWidth(31)),
      height: ScreenUtil().setWidth(130),
      decoration: BoxDecoration(
          border:
              Border(bottom: BorderSide(color: Colors.grey[200], width: 0.5))),
      child: Row(
        children: <Widget>[
          Text(leftTitle ?? "标题：", style: TextStyles.textGray37),
          SizedBox(width: ScreenUtil().setWidth(10)),
          Expanded(
            child: TextField(
              controller: textEditingController,
              maxLines: null,
              style: TextStyle(
                  color: Colors.black,
                  fontSize: ScreenUtil().setSp(43),
                  fontWeight: FontWeight.w400),
              decoration: InputDecoration(
                border: InputBorder.none,
                hintText: '',
                counterText: "", //此处控制最大字符是否显示
                hintStyle: TextStyle(
                  fontSize: ScreenUtil().setSp(43),
                  color: Colors.grey,
                ),
              ),
              onChanged: onChanged,
              onTap: () {
                if (MediaQuery.of(context).viewInsets.bottom > 0) {
                  FocusScope.of(context).requestFocus(FocusNode());
                }
              },
            ),
          )
        ],
      ),
    );
  }
}

///回复信件输入框
class ReplyInputBox extends StatelessWidget {
  final TextEditingController textEditingController;

  ReplyInputBox({this.textEditingController});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        height: ScreenUtil().setWidth(676),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(color: Colors.grey[200], width: 0.5))),
        margin: EdgeInsets.only(
            left: ScreenUtil().setWidth(31), right: ScreenUtil().setWidth(31)),
        child: TextField(
          controller: textEditingController,
          maxLines: null,
          style: TextStyles.textDark43,
          decoration: InputDecoration(
            border: InputBorder.none,
            hintText: '请输入内容',
            counterText: "", //此处控制最大字符是否显示
            hintStyle: TextStyles.textGray37,
          ),
        ),
      ),
      onTap: () {
        if (MediaQuery.of(context).viewInsets.bottom > 0) {
          FocusScope.of(context).requestFocus(FocusNode());
        }
      },
    );
  }
}

///左边提示，右边是输入框
class RightEditWidget extends StatelessWidget {
  final TextStyle leftTextStyle;
  final String rightTitle, hintText;
  final TextEditingController textEditingController;
  final bool enabled, visible;

  RightEditWidget(
      {this.leftTextStyle,
      this.hintText,
      this.visible,
      this.rightTitle,
      this.textEditingController,
      this.enabled});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 1),
      child: Row(
        children: <Widget>[
          Text(rightTitle ?? "", style: leftTextStyle ?? TextStyles.textGray37),
          Spacer(),
          Container(
            width: 100,
            child: TextField(
              enabled: enabled ?? true,
              controller: textEditingController,
              maxLines: 1,
              textAlign: TextAlign.end,
              style: TextStyle(
                  color: Colors.black,
                  fontSize: ScreenUtil().setSp(43),
                  fontWeight: FontWeight.w400),
              decoration: InputDecoration(
                border: InputBorder.none,
                hintText: hintText ?? '请输入昵称',
                counterText: "", //此处控制最大字符是否显示
                hintStyle: TextStyle(
                  fontSize: ScreenUtil().setSp(43),
                  color: Colors.grey,
                ),
              ),
              onTap: () {
                if (MediaQuery.of(context).viewInsets.bottom > 0) {
                  FocusScope.of(context).requestFocus(FocusNode());
                }
              },
            ),
          ),
          Visibility(
            child: Icon(Icons.chevron_right, color: Colors.grey),
            visible: visible ?? false,
          )
        ],
      ),
      color: Colors.white,
      padding: EdgeInsets.only(
        right: ScreenUtil().setWidth(35),
        left: ScreenUtil().setWidth(35),
      ),
    );
  }
}

class EditWidget extends StatefulWidget {
  final String hintText, textContent;
  final TextEditingController textEditingController;
  final bool autofocus;
  final bool inputBorder;

  EditWidget(
      {this.textContent,
      this.hintText,
      this.autofocus,
      this.inputBorder,
      this.textEditingController});

  @override
  _EditWidgetState createState() => _EditWidgetState();
}

class _EditWidgetState extends State<EditWidget> {
  @override
  Widget build(BuildContext context) {
    return TextField(
      autofocus: widget.autofocus ?? false,
      controller: widget.textEditingController,
      maxLines: 1,
      style: TextStyles.textDark43,
      decoration: widget.inputBorder ?? false
          ? InputDecoration(
              hintText: widget.hintText ?? '提示内容',
              counterText: "",
              //此处控制最大字符是否显示
              hintStyle: TextStyles.textGray37,
              contentPadding: EdgeInsets.only(left: 10))
          : InputDecoration(
              border: InputBorder.none,
              hintText: widget.hintText ?? '提示内容',
              counterText: "",
              //此处控制最大字符是否显示
              hintStyle: TextStyles.textGray37,
              contentPadding: EdgeInsets.only(left: 10)),
      onTap: () {
        if (MediaQuery.of(context).viewInsets.bottom > 0) {
          FocusScope.of(context).requestFocus(FocusNode());
        }
      },
    );
  }
}

class SwitchRowWidget extends StatelessWidget {
  final bool rightIcon;
  final String name;
  final String imageUrl;
  final String lcassName;

  SwitchRowWidget({this.rightIcon, this.name, this.imageUrl, this.lcassName});

  @override
  Widget build(BuildContext context) {
    MyAppViewModel myAppViewModel = Provider.of(context);
    return myAppViewModel.identity
        ? Row(
            children: <Widget>[
              Image.network(
                imageUrl ??
                    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1596695040186&di=f2c1537a9e4d684ef882d9f9d217cb44&imgtype=0&src=http%3A%2F%2Fa1.att.hudong.com%2F05%2F00%2F01300000194285122188000535877.jpg",
                height: ScreenUtil().setWidth(47),
                width: ScreenUtil().setWidth(47),
              ),
              SizedBox(width: ScreenUtil().setWidth(34)),
              Expanded(child: Text("$name", style: TextStyles.textDark43)),
              Visibility(
                  child: Icon(
                    Icons.check_circle,
                    color: Colors.blue,
                    size: ScreenUtil().setSp(30),
                  ),
                  visible: rightIcon ?? false)
            ],
          )
        : Row(
            children: [
              Text("$name", style: TextStyles.textDark43),
              Text("$lcassName", style: TextStyles.textGray37),
            ],
          );
  }
}

class ItemNameWidget extends StatelessWidget {
  final bool visibleJump, visibleStars, visibleRemind;
  final String title, content;
  final GestureTapCallback onTap, remindOnTap;

  ItemNameWidget(
      {this.visibleJump,
      this.title,
      this.remindOnTap,
      this.content,
      this.visibleStars,
      this.onTap,
      this.visibleRemind});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(
        top: ScreenUtil().setWidth(48),
        bottom: ScreenUtil().setWidth(48),
        left: ScreenUtil().setWidth(35),
        right: ScreenUtil().setWidth(35),
      ),
      margin: EdgeInsets.only(top: 1),
      child: GestureDetector(
        child: Row(
          children: <Widget>[
            Text(title ?? "请填充内容", style: TextStyles.textDark37),
            Expanded(
                child: Padding(
              child: Text(
                content == null ? "" : "提交于:" + content ?? "",
                style: TextStyles.textGray30,
              ),
              padding: EdgeInsets.only(left: 10, right: 10),
            )),
            Visibility(
              visible: visibleStars ?? false,
              child: Container(
                height: 35,
                margin: EdgeInsets.only(right: 10),
                child: ListView.builder(
                    scrollDirection: Axis.horizontal,
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: 3,
                    itemBuilder: (context, index) {
                      return Icon(Icons.star, size: 10, color: Colors.red);
                    }),
              ),
            ),
            Visibility(
              visible: visibleRemind ?? false,
              child: GestureDetector(
                child: Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    border: Border.all(color: Colors.blue, width: 0.5),
                  ),
                  padding:
                      EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 3),
                  child: Text("已提醒", style: TextStyles.textBlue30),
                ),
                onTap: () {
                  if (remindOnTap != null) {
                    remindOnTap();
                  }
                },
              ),
            ),
            Visibility(
              visible: visibleJump ?? false,
              child: Icon(Icons.arrow_forward_ios, size: 10),
            ),
          ],
        ),
        onTap: onTap,
      ),
    );
  }
}
